﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _Selfholdingtapers
    {
        public static void Selfholdingtapers(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层


            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            string bbxz = Convert.ToString(data["bbxz"]);
            double czc = Convert.ToDouble(data["czc"]);
            double bbxs = Convert.ToDouble(data["bbxs"]);

            double tg = 0;
            double D = 0;
            double a = 0;
            double D1 = 0;
            double D2 = 0;
            double d = 0;
            double d1 = 0;
            double d2 = 0;
            double d3 = 0;
            double d4 = 0;
            double d8 = 0;
            double d9 = 0;
            double d10 = 0;
            double l1 = 0;
            double l2 = 0;
            double l3 = 0;
            double l4 = 0;
            double l7 = 0;
            double l8 = 0;
            double l11 =0;
            double l12 = 0;
            double b = 0;
            double c = 0;
            double e = 0;
            double i = 0;
            double R = 0;
            double r = 0;
            double r1 = 0;
            double t = 0;
            double d5 = 0;
            double d6 = 0;
            double d7 = 0;
            double l5 = 0;
            double l6 = 0;
            double l9 = 0;
            double l10 = 0;
            double l13 = 0;
            double g = 0;
            double h = 0;
            double p = 0;
            double z = 0;

            if (czc == 0)
            {
                tg = 0.05205;
                D = 9.045;
                a = 3;
                D1 = 9.2;
                d = 6.4;
                d2 = 6.1;
                d3 = 6;
                d4 = 8;
                l1 = 50;
                l2 = 53;
                l4 = 59.5;
                b = 3.9;
                c = 6.5;
                e = 10.5;
                R = 4;
                r = 1;
                r1 = 0.2;
                t = 4;
                d5 = 6.7;
                l5 = 52;
                l6 = 49;
                g = 3.9;
                h = 15;
                z = 1;
            }
            if (czc == 1)
            {
                tg = 0.04988;
                D = 12.065;
                a = 3.5;
                D1 = 12.2;
                d = 9.4;
                d1 = 6;
                d2 = 9;
                d3 = 8.7;
                d4 = 9;
                d8 = 6.4;
                d9 = 8;
                d10 = 8.5;
                l1 = 53.5;
                l2 = 57;
                l3 = 62;
                l4 = 65.5;
                l11 = 4;
                b = 5.2;
                c = 8.5;
                e = 13.5;
                i = 16;
                R = 5;
                r = 1.2;
                r1 = 0.21;
                t = 5;
                d5 = 9.7;
                d6 = 7;
                d7 = 0;
                l5 = 56;
                l6 = 52;
                l9 = 0;
                l10 = 0;
                l13 = 0;
                g = 5.2;
                h = 19;
                p = 0;
                z = 1;
            }
            if (czc == 2)
            {
                tg = 0.04995;
                D = 17.78;
                a = 5;
                D1 = 18;
                D2 = 15;
                d = 14.6;
                d1 = 10;
                d2 = 14;
                d3 = 13.5;
                d4 = 14;
                d8 = 10.5;
                d9 = 12.5;
                d10 = 13.2;
                l1 = 64;
                l2 = 69;
                l3 = 75;
                l4 = 80;
                l7 = 20;
                l8 = 34;
                l11 = 5;
                l12 = 27;
                b = 6.3;
                c = 10;
                e = 10;
                i = 24;
                R = 6;
                r = 1.6;
                r1 = 0.21;
                t = 5;
                d5 = 14.9;
                d6 = 11.5;
                d7 = 19.5;
                l5 = 67;
                l6 = 62;
                l9 = 22;
                l10 = 32;
                l13 = 27;
                g = 6.3;
                h = 22;
                p = 4.2;
                z = 1;
            }
            if (czc == 3)
            {
                D = 23.825;
                a = 5;
                D1 = 24.1;
                D2 = 21;
                d = 19.8;
                d1 = 12;
                d2 = 19.1;
                d3 = 18.5;
                d4 = 19;
                d8 = 13;
                d9 = 15;
                d10 = 17;
                l1 = 81;
                l2 = 86;
                l3 = 94;
                l4 = 99;
                l7 = 29;
                l8 = 43;
                l11 = 5.5;
                l12 = 36;
                b = 7.9;
                c = 13;
                e = 20;
                i = 47;
                R = 18;
                r = 4;
                r1 = 4;
                t = 16;
                d5 = 20.2;
                d6 = 14;
                d7 = 24.5;
                l5 = 84;
                l6 = 78;
                l9 = 31;
                l10 = 41;
                l13 = 36;
                g = 7.9;
                h = 27;
                p = 5;
                z = 1;
                tg = 0.0502;
            }
            if (czc == 4)
            {
                D = 31.267;
                a = 6.5;
                D1 = 31.6;
                D2 = 28;
                d = 25.9;
                d1 = 16;
                d2 = 25.5;
                d3 = 24.5;
                d8 = 17; ;
                d9 = 20;
                d10 = 22;
                l1 = 102.5;
                l2 = 109;
                l3 = 117.5;
                l4 = 124;
                l7 = 39;
                l8 = 55;
                l11 = 8.2;
                l12 = 47;
                c = 16;
                e = 24;
                i = 32;
                R = 8;
                r = 2.5;
                r1 = 1;
                t = 9;
                d5 = 26.5;
                d6 = 18;
                d7 = 32;
                l5 = 107;
                l6 = 98;
                l9 = 41;
                l10 = 53;
                l13 = 47;
                g = 11.9;
                h = 32;
                p = 6.8;
                z = 1;
                tg = 0.5194;
            }
            if (czc == 5)
            {
                D = 44.399;
                a = 6.5;
                D1 = 44.7;
                D2 = 40;
                d = 37.6;
                d1 = 20;
                d2 = 36.5;
                d3 = 35.7;
                d8 = 21; ;
                d9 = 26;
                d10 = 30;
                l1 = 129.5;
                l2 = 136;
                l3 = 149.5;
                l4 = 156;
                l7 = 51;
                l8 = 69;
                l11 = 10;
                l12 = 60;
                c = 19;
                e = 29;
                i = 47;
                R = 18;
                r = 4;
                r1 = 2.5;
                t = 10;
                d5 = 38.2;
                d6 = 23;
                d7 = 44;
                l5 = 135;
                l6 = 125;
                l9 = 53;
                l10 = 67;
                l13 = 60;
                g = 15.9;
                h = 38;
                p = 8.5;
                z = 1;
                tg = 0.5263;
            }
            if (czc == 6)
            {
                D = 63.348;
                a = 8;
                D1 = 63.8;
                D2 = 56;
                d = 53.9;
                d1 = 24;
                d2 = 52.4;
                d3 = 51;
                d8 = 26; ;
                d9 = 31;
                d10 = 36;
                l1 = 182;
                l2 = 190;
                l3 = 210;
                l4 = 218;
                l7 = 81;
                l8 = 99;
                l11 = 11.5;
                l12 = 90;
                c = 27;
                e = 40;
                i = 47;
                R = 18;
                r = 4;
                r1 = 4;
                t = 16;
                d5 = 54.8;
                d6 = 27;
                d7 = 63;
                l5 = 188;
                l6 = 177;
                l9 = 83;
                l10 = 97;
                l13 = 90;
                g = 19;
                h = 47;
                p = 10.2;
                z = 1;
                tg = 0.5214;
            }
            if (bbxz == "nyz")
            {

                if (bbxs == 0)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + 1.5 * l5 + 4, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - 2, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D / 2);
                    Vector2 v5 = new Vector2(v4.X - (D - d5) / tg, v2.Y + d5 / 2);
                    Vector2 v6 = new Vector2(v4.X - l5, v5.Y);
                    Vector2 v7 = new Vector2(v6.X, v3.Y + g / 2);
                    Vector2 v8 = new Vector2(v7.X - l5 / 5, v7.Y);
                    Vector2 v9 = new Vector2(v8.X, v8.Y * -1);
                    Vector2 v10 = new Vector2(v7.X, v7.Y * -1);
                    Vector2 v11 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v12 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v13 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v14 = new Vector2(v4.X, v3.Y + D / 1.333);
                    Vector2 v15 = new Vector2(v14.X - l5 * 1.333, v14.Y);
                    Vector2 v16 = new Vector2(v15.X - l5 / 26.538, v15.Y - D / 3.333);
                    Vector2 v17 = new Vector2(v16.X, v16.Y * -1);
                    Vector2 v18 = new Vector2(v15.X, v15.Y * -1);
                    Vector2 v19 = new Vector2(v14.X, v14.Y * -1);



                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);


                    LwPolyline line2 = new LwPolyline();
                    line2.Vertexes.Add(new LwPolylineVertex(v7));
                    line2.Vertexes.Add(new LwPolylineVertex(v10));
                    line2.Vertexes.Add(new LwPolylineVertex(v9));
                    line2.Vertexes.Add(new LwPolylineVertex(v8));
                    line2.Vertexes.Add(new LwPolylineVertex(v7));
                    line2.Vertexes.Add(new LwPolylineVertex(v6));
                    line2.Vertexes.Add(new LwPolylineVertex(v5));
                    line2.Vertexes.Add(new LwPolylineVertex(v4));
                    line2.Vertexes.Add(new LwPolylineVertex(v13));
                    line2.Vertexes.Add(new LwPolylineVertex(v12));
                    line2.Vertexes.Add(new LwPolylineVertex(v11));
                    line2.Vertexes.Add(new LwPolylineVertex(v10));
                    line2.Vertexes.Add(new LwPolylineVertex(v11));
                    line2.Vertexes.Add(new LwPolylineVertex(v12));
                    line2.Vertexes.Add(new LwPolylineVertex(v5));
                    line2.Vertexes[0].Bulge = Math.Tan(-125 * pi / 180 / 4);
                    line2.Vertexes[2].Bulge = Math.Tan(-125 * pi / 180 / 4);
                    fun.PolyFill(dxf, line2, 0.1, contour);

                    LwPolyline line3 = new LwPolyline();
                    line3.Vertexes.Add(new LwPolylineVertex(v14));
                    line3.Vertexes.Add(new LwPolylineVertex(v15));
                    line3.Vertexes.Add(new LwPolylineVertex(v16));
                    line3.Vertexes.Add(new LwPolylineVertex(v17));
                    line3.Vertexes.Add(new LwPolylineVertex(v18));
                    line3.Vertexes.Add(new LwPolylineVertex(v19));
                    line3.Vertexes.Add(new LwPolylineVertex(v14));
                    line3.Vertexes[1].Bulge = Math.Tan(45 * pi / 180 / 4);
                    line3.Vertexes[2].Bulge = Math.Tan(-10 * pi / 180 / 4);
                    line3.Vertexes[3].Bulge = Math.Tan(45 * pi / 180 / 4);
                    fun.PolyFill(dxf, line3, 0.1, contour);

                    //填充
                    LwPolyline hatchpoly1 = new LwPolyline();
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v6));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v14));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v15));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v16));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v17));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v18));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v19));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v13));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v10));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
                    hatchpoly1.Vertexes[0].Bulge = Math.Tan(-125 * pi / 180 / 4);
                    hatchpoly1.Vertexes[7].Bulge = Math.Tan(45 * pi / 180 / 4);
                    hatchpoly1.Vertexes[8].Bulge = Math.Tan(-10 * pi / 180 / 4);
                    hatchpoly1.Vertexes[9].Bulge = Math.Tan(45 * pi / 180 / 4);
                    hatchpoly1.IsClosed = true;
                    String[] htype1 = new String[100];
                    Line[] hline1 = new Line[100];
                    Arc[] harc1 = new Arc[100];
                    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                    for (int I = 0; I < hnumst1; I++)
                    {
                        htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype1[I] == "Line")
                        {
                            hline1[I] = (Line)hatchpoly1.Explode()[I];
                        }
                        if (htype1[I] == "Arc")
                        {
                            harc1[I] = (Arc)hatchpoly1.Explode()[I];
                        }
                    }
                    fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);

                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;


                    LinearDimension dim1 = new LinearDimension(new Line(v8, v9), (v7.X - v8.X) / 2, -90, dimensionStyle);
                    dim1.UserText = "g = " + g;
                    dxf.AddEntity(dim1);

                    LinearDimension dim2 = new LinearDimension(new Line(v12, v5), (v4.X - v5.X) / 2, -90, dimensionStyle);
                    dim2.UserText = "d5 = " + d5;
                    dxf.AddEntity(dim2);

                    LinearDimension dim3 = new LinearDimension(new Line(v4, v13), offset, -90, dimensionStyle);
                    dim3.UserText = "D = " + D;
                    dxf.AddEntity(dim3);

                }
                if (bbxs == 1)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l5 * 5 / 4 + 4, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - 2, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D / 2);
                    Vector2 v5 = new Vector2(v4.X - (D - d5) / tg, v3.Y + d5 / 2);
                    Vector2 v6 = new Vector2(v3.X - l5, v5.Y);
                    Vector2 v7 = new Vector2(v6.X - l5 / 14.667, v3.Y + d6 / 2);
                    Vector2 v8 = new Vector2(v3.X - l5 * 5 / 4, v7.Y);
                    Vector2 v9 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v10 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v11 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v12 = new Vector2(v7.X, v7.Y * -1);
                    Vector2 v13 = new Vector2(v8.X, v8.Y * -1);
                    Vector2 v14 = new Vector2(v3.X, v3.Y - D);
                    Vector2 v15 = new Vector2(v13.X, v14.Y);
                    Vector2 v16 = new Vector2(v14.X, v14.Y * -1);
                    Vector2 v17 = new Vector2(v15.X, v15.Y * -1);


                    if (d6 == 0)
                    {
                        v8 = new Vector2(v17.X, v17.Y - D / 1.635);
                        v13 = new Vector2(v8.X, v8.Y * -1);
                    }
                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    LwPolyline line2 = new LwPolyline();
                    line2.Vertexes.Add(new LwPolylineVertex(v14));
                    line2.Vertexes.Add(new LwPolylineVertex(v15));
                    line2.Vertexes.Add(new LwPolylineVertex(v13));
                    line2.Vertexes.Add(new LwPolylineVertex(v8));
                    line2.Vertexes.Add(new LwPolylineVertex(v17));
                    line2.Vertexes.Add(new LwPolylineVertex(v16));
                    line2.Vertexes.Add(new LwPolylineVertex(v14));
                    line2.Vertexes[1].Bulge = Math.Tan(-25 * pi / 180 / 4);
                    line2.Vertexes[2].Bulge = Math.Tan(17 * pi / 180 / 4);
                    line2.Vertexes[3].Bulge = Math.Tan(-25 * pi / 180 / 4);
                    fun.PolyFill(dxf, line2, 0.1, contour);

                    if (d6 != 0)
                    {
                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v12));
                        line3.Vertexes.Add(new LwPolylineVertex(v13));
                        line3.Vertexes.Add(new LwPolylineVertex(v12));
                        line3.Vertexes.Add(new LwPolylineVertex(v11));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v10));
                        line3.Vertexes.Add(new LwPolylineVertex(v11));
                        line3.Vertexes.Add(new LwPolylineVertex(v10));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v4));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        fun.PolyFill(dxf, line3, 0.1, contour);
                    }

                    if (d6 == 0)
                    {
                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v11));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v10));
                        line3.Vertexes.Add(new LwPolylineVertex(v11));
                        line3.Vertexes.Add(new LwPolylineVertex(v10));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v4));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        fun.PolyFill(dxf, line3, 0.1, contour);
                    }

                    //填充
                    if (d6 == 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v13));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v9));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v6));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v16));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly1.Vertexes[0].Bulge = Math.Tan(25 * pi / 180 / 4);
                        hatchpoly1.Vertexes[1].Bulge = Math.Tan(-17 * pi / 180 / 4);
                        hatchpoly1.Vertexes[2].Bulge = Math.Tan(25 * pi / 180 / 4);
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);
                    }


                    if (d6 != 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v6));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v16));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly1.Vertexes[0].Bulge = Math.Tan(25 * pi / 180 / 4);
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);


                        LwPolyline hatchpoly2 = new LwPolyline();
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v13));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v9));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v10));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v11));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v12));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v13));
                        hatchpoly2.Vertexes[0].Bulge = Math.Tan(25 * pi / 180 / 4);
                        hatchpoly2.IsClosed = true;
                        String[] htype2 = new String[100];
                        Line[] hline2 = new Line[100];
                        Arc[] harc2 = new Arc[100];
                        int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst2; I++)
                        {
                            htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype2[I] == "Line")
                            {
                                hline2[I] = (Line)hatchpoly2.Explode()[I];
                            }
                            if (htype2[I] == "Arc")
                            {
                                harc2[I] = (Arc)hatchpoly2.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);

                    }

                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;

                    if (d6 != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v8, v13), (v7.X - v8.X) / 2, 90, dimensionStyle);
                        dim1.UserText = "d6 = " + d6;
                        dxf.AddEntity(dim1);
                    }
                    LinearDimension dim2 = new LinearDimension(new Line(v10, v5), (v5.X - v6.X) / 3, 90, dimensionStyle);
                    dim2.UserText = "d5 = " + d5;
                    dxf.AddEntity(dim2);

                    LinearDimension dim3 = new LinearDimension(new Line(v4, v9), offset, -90, dimensionStyle);
                    dim3.UserText = "D = " + D;
                    dxf.AddEntity(dim3);

                    LinearDimension dim4 = new LinearDimension(new Line(v11, v14), D * 2, 180, dimensionStyle);
                    dim4.UserText = "l5 = " + l5;
                    dxf.AddEntity(dim4);


                }
                if (bbxs == 2)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l5 * 4 / 3 + 6, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - 3, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D / 2);
                    Vector2 v11 = new Vector2(v4.X - (D - d5) / tg, v3.Y + d5 / 2);
                    Vector2 v5 = new Vector2(0, 0);
                    Vector2 v6 = new Vector2(0, 0);
                    Vector2 v7 = new Vector2(0, 0);
                    Vector2 v8 = new Vector2(0, 0);
                    Vector2 v9 = new Vector2(0, 0);
                    Vector2 v10 = new Vector2(0, 0);
                    Vector2 v16 = new Vector2(0, 0);
                    Vector2 v17 = new Vector2(0, 0);
                    Vector2 v18 = new Vector2(0, 0);
                    Vector2 v19 = new Vector2(0, 0);
                    Vector2 v27 = new Vector2(0, 0);
                    Vector2 v28 = new Vector2(0, 0);
                    Vector2 v34 = new Vector2(0, 0);
                    Vector2 v35 = new Vector2(0, 0);
                    if (p != 0)
                    {
                        v5 = new Vector2(v4.X - l9, v3.Y + (D - l9 * tg) / 2);
                        v6 = new Vector2(v5.X - (l13 - p / 2 - l9) / 2, v3.Y + d7 / 2);
                        v7 = new Vector2(v3.X - l13 + p / 2, v6.Y);
                        v8 = new Vector2(v7.X - p, v7.Y);
                        v9 = new Vector2(v8.X - (l10 - l13 - p / 2) / 2, v8.Y);
                        v10 = new Vector2(v3.X - l10, v3.Y + v5.Y - (l10 - l9) * tg / 2);
                        v11 = new Vector2(v10.X - (v10.Y * 2 - d5) / tg, v3.Y + d5 / 2);
                        v16 = new Vector2(v5.X, v5.Y * -1);
                        v17 = new Vector2(v6.X, v6.Y * -1);
                        v18 = new Vector2(v9.X, v9.Y * -1);
                        v19 = new Vector2(v10.X, v10.Y * -1);
                        v27 = new Vector2(v7.X, v3.Y + D / 1.187);
                        v28 = new Vector2(v8.X, v27.Y);
                        v34 = new Vector2(v27.X - p / 2, v27.Y + 2);
                        v35 = new Vector2(v34.X, v6.Y - 3);
                    }
                    Vector2 v12 = new Vector2(v3.X - l5, v11.Y);
                    Vector2 v13 = new Vector2(v12.X, v3.Y + g / 2);
                    Vector2 v14 = new Vector2(v13.X - l5 / 5, v13.Y);
                    Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v20 = new Vector2(v11.X, v11.Y * -1);
                    Vector2 v21 = new Vector2(v12.X, v12.Y * -1);
                    Vector2 v22 = new Vector2(v13.X, v13.Y * -1);
                    Vector2 v23 = new Vector2(v14.X, v14.Y * -1);
                    Vector2 v24 = new Vector2(v12.X - (v12.Y - v13.Y), v13.Y);
                    Vector2 v25 = new Vector2(v24.X, v24.Y * -1);
                    Vector2 v26 = new Vector2(v3.X, v3.Y + D / 1.187);
                    Vector2 v29 = new Vector2(v3.X - l5 * 4 / 3, v26.Y);
                    Vector2 v30 = new Vector2(v26.X, v26.Y * -1);
                    Vector2 v31 = new Vector2(v29.X, v29.Y * -1);
                    Vector2 v32 = new Vector2(v31.X, v31.Y + (v29.Y - v31.Y) / 3);
                    Vector2 v33 = new Vector2(v32.X, v32.Y * -1);
                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    if (p != 0)
                    {
                        LwPolyline line2 = new LwPolyline();
                        line2.Vertexes.Add(new LwPolylineVertex(v4));
                        line2.Vertexes.Add(new LwPolylineVertex(v5));
                        line2.Vertexes.Add(new LwPolylineVertex(v16));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        fun.PolyFill(dxf, line2, 0.1, contour);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v18));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes[7].Bulge = Math.Tan(129 * pi / 180 / 4);
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v9));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        line4.Vertexes.Add(new LwPolylineVertex(v18));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        line4.Vertexes.Add(new LwPolylineVertex(v20));
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v12));
                        line4.Vertexes.Add(new LwPolylineVertex(v13));
                        line4.Vertexes.Add(new LwPolylineVertex(v24));
                        line4.Vertexes.Add(new LwPolylineVertex(v12));
                        fun.PolyFill(dxf, line4, 0.1, contour);

                        LwPolyline line5 = new LwPolyline();
                        line5.Vertexes.Add(new LwPolylineVertex(v20));
                        line5.Vertexes.Add(new LwPolylineVertex(v21));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes.Add(new LwPolylineVertex(v25));
                        line5.Vertexes.Add(new LwPolylineVertex(v21));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes.Add(new LwPolylineVertex(v23));
                        line5.Vertexes.Add(new LwPolylineVertex(v14));
                        line5.Vertexes.Add(new LwPolylineVertex(v13));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes[6].Bulge = Math.Tan(-180 * pi / 180 / 4);
                        line5.Vertexes[8].Bulge = Math.Tan(-180 * pi / 180 / 4);
                        fun.PolyFill(dxf, line5, 0.1, contour);

                        LwPolyline line6 = new LwPolyline();
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes.Add(new LwPolylineVertex(v27));
                        line6.Vertexes.Add(new LwPolylineVertex(v28));
                        line6.Vertexes.Add(new LwPolylineVertex(v29));
                        line6.Vertexes.Add(new LwPolylineVertex(v33));
                        line6.Vertexes.Add(new LwPolylineVertex(v32));
                        line6.Vertexes.Add(new LwPolylineVertex(v31));
                        line6.Vertexes.Add(new LwPolylineVertex(v30));
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes[1].Bulge = Math.Tan(-129 * pi / 180 / 4);
                        line6.Vertexes[3].Bulge = Math.Tan(34 * pi / 180 / 4);
                        line6.Vertexes[4].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        line6.Vertexes[5].Bulge = Math.Tan(34 * pi / 180 / 4);
                        fun.PolyFill(dxf, line6, 0.1, contour);

                        LwPolyline line7 = new LwPolyline();
                        line7.Vertexes.Add(new LwPolylineVertex(v28));
                        line7.Vertexes.Add(new LwPolylineVertex(v8));
                        fun.PolyFill(dxf, line7, 0.1, contour);

                        LwPolyline line8 = new LwPolyline();
                        line8.Vertexes.Add(new LwPolylineVertex(v27));
                        line8.Vertexes.Add(new LwPolylineVertex(v7));
                        fun.PolyFill(dxf, line8, 0.1, contour);

                        Line line9 = new Line(v34, v35);
                        line9.Layer = centre;
                        line9.Linetype = Linetype.DashDot;
                        line9.LinetypeScale = 3;
                        dxf.AddEntity(line9);
                    }
                    if (p == 0)
                    {
                        LwPolyline line2 = new LwPolyline();
                        line2.Vertexes.Add(new LwPolylineVertex(v4));
                        line2.Vertexes.Add(new LwPolylineVertex(v11));
                        line2.Vertexes.Add(new LwPolylineVertex(v20));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        fun.PolyFill(dxf, line2, 0.1, contour);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v18));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes[7].Bulge = Math.Tan(129 * pi / 180 / 4);
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v26));
                        line4.Vertexes.Add(new LwPolylineVertex(v29));
                        line4.Vertexes.Add(new LwPolylineVertex(v33));
                        line4.Vertexes.Add(new LwPolylineVertex(v32));
                        line4.Vertexes.Add(new LwPolylineVertex(v31));
                        line4.Vertexes.Add(new LwPolylineVertex(v30));
                        line4.Vertexes.Add(new LwPolylineVertex(v26));
                        line4.Vertexes[1].Bulge = Math.Tan(34 * pi / 180 / 4);
                        line4.Vertexes[2].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        line4.Vertexes[3].Bulge = Math.Tan(34 * pi / 180 / 4);
                        fun.PolyFill(dxf, line4, 0.1, contour);

                        LwPolyline line5 = new LwPolyline();
                        line5.Vertexes.Add(new LwPolylineVertex(v20));
                        line5.Vertexes.Add(new LwPolylineVertex(v21));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes.Add(new LwPolylineVertex(v25));
                        line5.Vertexes.Add(new LwPolylineVertex(v21));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes.Add(new LwPolylineVertex(v23));
                        line5.Vertexes.Add(new LwPolylineVertex(v14));
                        line5.Vertexes.Add(new LwPolylineVertex(v13));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes[6].Bulge = Math.Tan(-180 * pi / 180 / 4);
                        line5.Vertexes[8].Bulge = Math.Tan(-180 * pi / 180 / 4);
                        fun.PolyFill(dxf, line5, 0.1, contour);

                        LwPolyline line6 = new LwPolyline();
                        line6.Vertexes.Add(new LwPolylineVertex(v11));
                        line6.Vertexes.Add(new LwPolylineVertex(v12));
                        line6.Vertexes.Add(new LwPolylineVertex(v13));
                        line6.Vertexes.Add(new LwPolylineVertex(v24));
                        line6.Vertexes.Add(new LwPolylineVertex(v12));
                        fun.PolyFill(dxf, line6, 0.1, contour);

                    }

                    //填充
                    if (p == 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v24));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v23));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v21));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v20));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v30));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v31));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v32));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v33));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v29));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes[4].Bulge = Math.Tan(180 * pi / 180 / 4);
                        hatchpoly1.Vertexes[11].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        hatchpoly1.Vertexes[12].Bulge = Math.Tan(34 * pi / 180 / 4);
                        hatchpoly1.Vertexes[13].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);
                    }


                    if (p != 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v6));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);


                        LwPolyline hatchpoly2 = new LwPolyline();
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v9));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v10));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v11));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v12));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v24));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v23));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v25));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v21));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v20));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v19));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v18));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v16));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v30));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v31));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v32));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v33));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v29));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly2.Vertexes[6].Bulge = Math.Tan(180 * pi / 180 / 4);
                        hatchpoly2.Vertexes[17].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        hatchpoly2.Vertexes[18].Bulge = Math.Tan(34 * pi / 180 / 4);
                        hatchpoly2.Vertexes[19].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        hatchpoly2.IsClosed = true;
                        String[] htype2 = new String[100];
                        Line[] hline2 = new Line[100];
                        Arc[] harc2 = new Arc[100];
                        int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst2; I++)
                        {
                            htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype2[I] == "Line")
                            {
                                hline2[I] = (Line)hatchpoly2.Explode()[I];
                            }
                            if (htype2[I] == "Arc")
                            {
                                harc2[I] = (Arc)hatchpoly2.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);

                    }
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;

                    if (p != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v5, v26), D / 2, 0, dimensionStyle);
                        dim1.UserText = "l9 = " + l9;
                        dxf.AddEntity(dim1);

                        LinearDimension dim2 = new LinearDimension(new Line(v8, v7), D / 2, 0, dimensionStyle);
                        dim2.UserText = "P = " + p;
                        dxf.AddEntity(dim2);

                        LinearDimension dim3 = new LinearDimension(new Line(v10, v26), D * 1.5, 0, dimensionStyle);
                        dim3.UserText = "l10 = " + l10;
                        dxf.AddEntity(dim3);

                        LinearDimension dim4 = new LinearDimension(new Line(v34, v26), D, 0, dimensionStyle);
                        dim4.UserText = "l13 = " + l13;
                        dxf.AddEntity(dim4);

                        LinearDimension dim7 = new LinearDimension(new Line(v9, v18), D / 2, 90, dimensionStyle);
                        dim7.UserText = "d7 = " + d7;
                        dxf.AddEntity(dim7);


                    }
                    LinearDimension dim5 = new LinearDimension(new Line(v24, v25), 0, 90, dimensionStyle);
                    dim5.UserText = "g = " + g;
                    dxf.AddEntity(dim5);

                    LinearDimension dim6 = new LinearDimension(new Line(v11, v20), D / 2, -90, dimensionStyle);
                    dim6.UserText = "d5 = " + d5;
                    dxf.AddEntity(dim6);

                    LinearDimension dim8 = new LinearDimension(new Line(v4, v15), D / 2, -90, dimensionStyle);
                    dim8.UserText = "D = " + D;
                    dxf.AddEntity(dim8);

                    LinearDimension dim9 = new LinearDimension(new Line(v21, v30), D, 180, dimensionStyle);
                    dim9.UserText = "l5 = " + l5;
                    dxf.AddEntity(dim9);



                }
                if (bbxs == 3)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l5 * 4 / 3 + 6, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - 3, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D / 2);
                    Vector2 v11 = new Vector2(v4.X - (D - d5) / tg, v3.Y + d5 / 2);
                    Vector2 v5 = new Vector2(0, 0);
                    Vector2 v6 = new Vector2(0, 0);
                    Vector2 v7 = new Vector2(0, 0);
                    Vector2 v8 = new Vector2(0, 0);
                    Vector2 v9 = new Vector2(0, 0);
                    Vector2 v10 = new Vector2(0, 0);
                    Vector2 v16 = new Vector2(0, 0);
                    Vector2 v17 = new Vector2(0, 0);
                    Vector2 v18 = new Vector2(0, 0);
                    Vector2 v19 = new Vector2(0, 0);
                    Vector2 v27 = new Vector2(0, 0);
                    Vector2 v28 = new Vector2(0, 0);
                    Vector2 v34 = new Vector2(0, 0);
                    Vector2 v35 = new Vector2(0, 0);
                    if (p != 0)
                    {
                        v5 = new Vector2(v4.X - l9, v3.Y + (D - l9 * tg) / 2);
                        v6 = new Vector2(v5.X - (l13 - p / 2 - l9) / 2, v3.Y + d7 / 2);
                        v7 = new Vector2(v3.X - l13 + p / 2, v6.Y);
                        v8 = new Vector2(v7.X - p, v7.Y);
                        v9 = new Vector2(v8.X - (l10 - l13 - p / 2) / 2, v8.Y);
                        v10 = new Vector2(v3.X - l10, v3.Y + v5.Y - (l10 - l9) * tg / 2);
                        v11 = new Vector2(v10.X - (v10.Y * 2 - d5) / tg, v3.Y + d5 / 2);
                        v16 = new Vector2(v5.X, v5.Y * -1);
                        v17 = new Vector2(v6.X, v6.Y * -1);
                        v18 = new Vector2(v9.X, v9.Y * -1);
                        v19 = new Vector2(v10.X, v10.Y * -1);
                        v27 = new Vector2(v7.X, v3.Y + D / 1.187);
                        v28 = new Vector2(v8.X, v27.Y);
                        v34 = new Vector2(v27.X - p / 2, v27.Y + 2);
                        v35 = new Vector2(v34.X, v6.Y - 3);
                    }
                    Vector2 v12 = new Vector2(v3.X - l5, v11.Y);
                    Vector2 v13 = new Vector2(v12.X - (v12.Y - d6 / 2), v3.Y + d6 / 2);
                    Vector2 v14 = new Vector2(v13.X, v13.Y * -1);
                    Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v20 = new Vector2(v11.X, v11.Y * -1);
                    Vector2 v21 = new Vector2(v12.X, v12.Y * -1);
                    Vector2 v26 = new Vector2(v3.X, v3.Y + D / 1.187);
                    Vector2 v29 = new Vector2(v3.X - l5 * 4 / 3, v26.Y);
                    Vector2 v30 = new Vector2(v26.X, v26.Y * -1);
                    Vector2 v31 = new Vector2(v29.X, v29.Y * -1);
                    Vector2 v33 = new Vector2(v29.X, v13.Y);
                    Vector2 v32 = new Vector2(v33.X, v33.Y * -1);
                    if (d6 == 0)
                    {
                        v33 = new Vector2(v29.X, v3.Y + (d5 / 1.385) / 2);
                        v32 = new Vector2(v33.X, v33.Y * -1);
                    }
                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    if (p != 0)
                    {
                        LwPolyline line2 = new LwPolyline();
                        line2.Vertexes.Add(new LwPolylineVertex(v4));
                        line2.Vertexes.Add(new LwPolylineVertex(v5));
                        line2.Vertexes.Add(new LwPolylineVertex(v16));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        fun.PolyFill(dxf, line2, 0.1, contour);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v18));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes[7].Bulge = Math.Tan(129 * pi / 180 / 4);
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v9));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        line4.Vertexes.Add(new LwPolylineVertex(v18));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        line4.Vertexes.Add(new LwPolylineVertex(v20));
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v12));
                        line4.Vertexes.Add(new LwPolylineVertex(v13));
                        line4.Vertexes.Add(new LwPolylineVertex(v33));
                        line4.Vertexes.Add(new LwPolylineVertex(v13));
                        line4.Vertexes.Add(new LwPolylineVertex(v14));
                        line4.Vertexes.Add(new LwPolylineVertex(v21));
                        line4.Vertexes.Add(new LwPolylineVertex(v14));
                        line4.Vertexes.Add(new LwPolylineVertex(v32));
                        fun.PolyFill(dxf, line4, 0.1, contour);

                        LwPolyline line6 = new LwPolyline();
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes.Add(new LwPolylineVertex(v27));
                        line6.Vertexes.Add(new LwPolylineVertex(v28));
                        line6.Vertexes.Add(new LwPolylineVertex(v29));
                        line6.Vertexes.Add(new LwPolylineVertex(v33));
                        line6.Vertexes.Add(new LwPolylineVertex(v32));
                        line6.Vertexes.Add(new LwPolylineVertex(v31));
                        line6.Vertexes.Add(new LwPolylineVertex(v30));
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes[1].Bulge = Math.Tan(-129 * pi / 180 / 4);
                        line6.Vertexes[3].Bulge = Math.Tan(34 * pi / 180 / 4);
                        line6.Vertexes[4].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        line6.Vertexes[5].Bulge = Math.Tan(34 * pi / 180 / 4);
                        fun.PolyFill(dxf, line6, 0.1, contour);

                        LwPolyline line7 = new LwPolyline();
                        line7.Vertexes.Add(new LwPolylineVertex(v28));
                        line7.Vertexes.Add(new LwPolylineVertex(v8));
                        fun.PolyFill(dxf, line7, 0.1, contour);

                        LwPolyline line8 = new LwPolyline();
                        line8.Vertexes.Add(new LwPolylineVertex(v27));
                        line8.Vertexes.Add(new LwPolylineVertex(v7));
                        fun.PolyFill(dxf, line8, 0.1, contour);

                        Line line9 = new Line(v34, v35);
                        line9.Layer = centre;
                        line9.Linetype = Linetype.DashDot;
                        line9.LinetypeScale = 3;
                        dxf.AddEntity(line9);

                        LwPolyline line10 = new LwPolyline();
                        line10.Vertexes.Add(new LwPolylineVertex(v12));
                        line10.Vertexes.Add(new LwPolylineVertex(v21));
                        line10.Vertexes.Add(new LwPolylineVertex(v20));
                        fun.PolyFill(dxf, line10, 0.1, contour);

                    }
                    if (p == 0)
                    {
                        LwPolyline line2 = new LwPolyline();
                        line2.Vertexes.Add(new LwPolylineVertex(v4));
                        line2.Vertexes.Add(new LwPolylineVertex(v11));
                        line2.Vertexes.Add(new LwPolylineVertex(v20));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        fun.PolyFill(dxf, line2, 0.1, contour);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v18));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes[7].Bulge = Math.Tan(129 * pi / 180 / 4);
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v26));
                        line4.Vertexes.Add(new LwPolylineVertex(v29));
                        line4.Vertexes.Add(new LwPolylineVertex(v33));
                        line4.Vertexes.Add(new LwPolylineVertex(v32));
                        line4.Vertexes.Add(new LwPolylineVertex(v31));
                        line4.Vertexes.Add(new LwPolylineVertex(v30));
                        line4.Vertexes.Add(new LwPolylineVertex(v26));
                        line4.Vertexes[1].Bulge = Math.Tan(34 * pi / 180 / 4);
                        line4.Vertexes[2].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        line4.Vertexes[3].Bulge = Math.Tan(34 * pi / 180 / 4);
                        fun.PolyFill(dxf, line4, 0.1, contour);

                        if (d6 != 0)
                        {
                            LwPolyline line5 = new LwPolyline();
                            line5.Vertexes.Add(new LwPolylineVertex(v21));
                            line5.Vertexes.Add(new LwPolylineVertex(v12));
                            line5.Vertexes.Add(new LwPolylineVertex(v11));
                            line5.Vertexes.Add(new LwPolylineVertex(v20));
                            line5.Vertexes.Add(new LwPolylineVertex(v21));
                            line5.Vertexes.Add(new LwPolylineVertex(v14));
                            line5.Vertexes.Add(new LwPolylineVertex(v32));
                            line5.Vertexes.Add(new LwPolylineVertex(v14));
                            line5.Vertexes.Add(new LwPolylineVertex(v13));
                            line5.Vertexes.Add(new LwPolylineVertex(v12));
                            line5.Vertexes.Add(new LwPolylineVertex(v13));
                            line5.Vertexes.Add(new LwPolylineVertex(v33));
                            fun.PolyFill(dxf, line5, 0.1, contour);
                        }
                        if (d6 == 0)
                        {
                            LwPolyline line5 = new LwPolyline();
                            line5.Vertexes.Add(new LwPolylineVertex(v21));
                            line5.Vertexes.Add(new LwPolylineVertex(v12));
                            line5.Vertexes.Add(new LwPolylineVertex(v11));
                            line5.Vertexes.Add(new LwPolylineVertex(v20));
                            line5.Vertexes.Add(new LwPolylineVertex(v21));
                            fun.PolyFill(dxf, line5, 0.1, contour);
                        }

                    }

                    //填充
                    if (p == 0)
                    {
                        if (d6 != 0)
                        {
                            LwPolyline hatchpoly1 = new LwPolyline();
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v13));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v33));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v29));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                            hatchpoly1.Vertexes[4].Bulge = Math.Tan(-34 * pi / 180 / 4);
                            hatchpoly1.IsClosed = true;
                            String[] htype1 = new String[100];
                            Line[] hline1 = new Line[100];
                            Arc[] harc1 = new Arc[100];
                            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                            for (int I = 0; I < hnumst1; I++)
                            {
                                htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype1[I] == "Line")
                                {
                                    hline1[I] = (Line)hatchpoly1.Explode()[I];
                                }
                                if (htype1[I] == "Arc")
                                {
                                    harc1[I] = (Arc)hatchpoly1.Explode()[I];
                                }
                            }
                            fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);

                            LwPolyline hatchpoly2 = new LwPolyline();
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v20));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v21));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v14));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v32));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v31));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v30));
                            hatchpoly2.Vertexes.Add(new LwPolylineVertex(v15));
                            hatchpoly2.Vertexes[4].Bulge = Math.Tan(34 * pi / 180 / 4);
                            hatchpoly2.IsClosed = true;
                            String[] htype2 = new String[100];
                            Line[] hline2 = new Line[100];
                            Arc[] harc2 = new Arc[100];
                            int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                            for (int I = 0; I < hnumst2; I++)
                            {
                                htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype2[I] == "Line")
                                {
                                    hline2[I] = (Line)hatchpoly2.Explode()[I];
                                }
                                if (htype2[I] == "Arc")
                                {
                                    harc2[I] = (Arc)hatchpoly2.Explode()[I];
                                }
                            }
                            fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);
                        }
                        if (d6 == 0)
                        {
                            LwPolyline hatchpoly1 = new LwPolyline();
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v11));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v12));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v21));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v20));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v15));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v30));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v31));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v32));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v33));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v29));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                            hatchpoly1.Vertexes[7].Bulge = Math.Tan(-34 * pi / 180 / 4);
                            hatchpoly1.Vertexes[8].Bulge = Math.Tan(34 * pi / 180 / 4);
                            hatchpoly1.Vertexes[9].Bulge = Math.Tan(-34 * pi / 180 / 4);
                            hatchpoly1.IsClosed = true;
                            String[] htype1 = new String[100];
                            Line[] hline1 = new Line[100];
                            Arc[] harc1 = new Arc[100];
                            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                            for (int I = 0; I < hnumst1; I++)
                            {
                                htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype1[I] == "Line")
                                {
                                    hline1[I] = (Line)hatchpoly1.Explode()[I];
                                }
                                if (htype1[I] == "Arc")
                                {
                                    harc1[I] = (Arc)hatchpoly1.Explode()[I];
                                }
                            }
                            fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);

                        }

                    }


                    if (p != 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v5));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v6));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v4));
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);


                        LwPolyline hatchpoly2 = new LwPolyline();
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v9));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v10));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v11));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v12));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v13));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v33));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v29));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly2.Vertexes[6].Bulge = Math.Tan(-34 * pi / 180 / 4);
                        hatchpoly2.IsClosed = true;
                        String[] htype2 = new String[100];
                        Line[] hline2 = new Line[100];
                        Arc[] harc2 = new Arc[100];
                        int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst2; I++)
                        {
                            htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype2[I] == "Line")
                            {
                                hline2[I] = (Line)hatchpoly2.Explode()[I];
                            }
                            if (htype2[I] == "Arc")
                            {
                                harc2[I] = (Arc)hatchpoly2.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);

                        LwPolyline hatchpoly3 = new LwPolyline();
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v16));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v17));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v18));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v19));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v20));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v21));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v32));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v31));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v30));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v15));
                        hatchpoly3.Vertexes[8].Bulge = Math.Tan(34 * pi / 180 / 4);
                        hatchpoly3.IsClosed = true;
                        String[] htype3 = new String[100];
                        Line[] hline3 = new Line[100];
                        Arc[] harc3 = new Arc[100];
                        int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst3; I++)
                        {
                            htype3[I] = hatchpoly3.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype3[I] == "Line")
                            {
                                hline3[I] = (Line)hatchpoly3.Explode()[I];
                            }
                            if (htype3[I] == "Arc")
                            {
                                harc3[I] = (Arc)hatchpoly3.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype3, hnumst3, 45, 10, hline3, harc3, hatching);

                    }
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;

                    if (p != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v5, v26), D / 2, 0, dimensionStyle);
                        dim1.UserText = "l9 = " + l9;
                        dxf.AddEntity(dim1);

                        LinearDimension dim2 = new LinearDimension(new Line(v8, v7), D / 2, 0, dimensionStyle);
                        dim2.UserText = "P = " + p;
                        dxf.AddEntity(dim2);

                        LinearDimension dim3 = new LinearDimension(new Line(v10, v26), D * 1.5, 0, dimensionStyle);
                        dim3.UserText = "l10 = " + l10;
                        dxf.AddEntity(dim3);

                        LinearDimension dim4 = new LinearDimension(new Line(v34, v26), D, 0, dimensionStyle);
                        dim4.UserText = "l13 = " + l13;
                        dxf.AddEntity(dim4);

                        LinearDimension dim7 = new LinearDimension(new Line(v9, v18), D / 2, 90, dimensionStyle);
                        dim7.UserText = "d7 = " + d7;
                        dxf.AddEntity(dim7);

                    }

                    LinearDimension dim5 = new LinearDimension(new Line(v13, v14), 0, 90, dimensionStyle);
                    dim5.UserText = "d6 = " + d6;
                    dxf.AddEntity(dim5);

                    LinearDimension dim8 = new LinearDimension(new Line(v4, v15), D / 2, -90, dimensionStyle);
                    dim8.UserText = "D = " + D;
                    dxf.AddEntity(dim8);

                    LinearDimension dim9 = new LinearDimension(new Line(v21, v30), D, 180, dimensionStyle);
                    dim9.UserText = "l5 = " + l5;
                    dxf.AddEntity(dim9);

                }
            }
            if (bbxz == "wyz")
            {

                if (bbxs == 0)
                {
                    l3 = (D - d2) / tg + e;
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l3 * 5 / 4, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - l3 / 6.155, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D1 / 2);
                    Vector2 v18 = new Vector2(v4.X - a, v3.Y + D / 2);
                    Vector2 v5 = new Vector2(v18.X - (D - d2) / tg, v3.Y + d2 / 2);
                    Vector2 v6 = new Vector2(v5.X - e / 4.782, v3.Y + b / 2);
                    Vector2 v20 = new Vector2(v5.X - e, v1.Y);
                    Vector2 v7 = new Vector2(v20.X + e / 6.889, v6.Y);
                    Vector2 v8 = new Vector2(v7.X, v7.Y * -1);
                    Vector2 v9 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v10 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v11 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v19 = new Vector2(v18.X, v18.Y * -1);
                    Vector2 v12 = new Vector2(v11.X + a / 1.65, v11.Y + D1 / 9.286);
                    Vector2 v13 = new Vector2(v12.X + a * 1.515, v12.Y);
                    Vector2 v14 = new Vector2(v13.X - a / 38.182, v13.Y + D1 / 3.457);
                    Vector2 v15 = new Vector2(v14.X, v14.Y * -1);
                    Vector2 v16 = new Vector2(v13.X, v13.Y * -1);
                    Vector2 v17 = new Vector2(v12.X, v12.Y * -1);



                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    LwPolyline line2 = new LwPolyline();
                    line2.Vertexes.Add(new LwPolylineVertex(v7));
                    line2.Vertexes.Add(new LwPolylineVertex(v6));
                    line2.Vertexes.Add(new LwPolylineVertex(v9));
                    line2.Vertexes.Add(new LwPolylineVertex(v8));
                    fun.PolyFill(dxf, line2, 0.1, contour);


                    Arc arc1 = fun.DrawArc3(v7, v20, v8);
                    fun.drawBArc(dxf, arc1, 0.1, contour);

                    Arc arc2 = fun.DrawArc4(v6, R, v5, 0);
                    fun.drawBArc(dxf, arc2, 0.1, contour);

                    Arc arc3 = fun.DrawArc4(v10, R, v9, 0);
                    fun.drawBArc(dxf, arc3, 0.1, contour);

                    LwPolyline line3 = new LwPolyline();
                    line3.Vertexes.Add(new LwPolylineVertex(v5));
                    line3.Vertexes.Add(new LwPolylineVertex(v18));
                    line3.Vertexes.Add(new LwPolylineVertex(v4));
                    line3.Vertexes.Add(new LwPolylineVertex(v11));
                    line3.Vertexes.Add(new LwPolylineVertex(v19));
                    line3.Vertexes.Add(new LwPolylineVertex(v10));
                    fun.PolyFill(dxf, line3, 0.1, contour);

                    LwPolyline line4 = new LwPolyline();
                    line4.Vertexes.Add(new LwPolylineVertex(v4));
                    line4.Vertexes.Add(new LwPolylineVertex(v17));
                    line4.Vertexes.Add(new LwPolylineVertex(v16));
                    line4.Vertexes.Add(new LwPolylineVertex(v15));
                    line4.Vertexes.Add(new LwPolylineVertex(v14));
                    line4.Vertexes.Add(new LwPolylineVertex(v13));
                    line4.Vertexes.Add(new LwPolylineVertex(v12));
                    line4.Vertexes.Add(new LwPolylineVertex(v11));
                    line4.Vertexes[0].Bulge = Math.Tan(74 * pi / 180 / 4);
                    line4.Vertexes[2].Bulge = Math.Tan(-38 * pi / 180 / 4);
                    line4.Vertexes[3].Bulge = Math.Tan(48 * pi / 180 / 4);
                    line4.Vertexes[4].Bulge = Math.Tan(-38 * pi / 180 / 4);
                    line4.Vertexes[6].Bulge = Math.Tan(74 * pi / 180 / 4);
                    fun.PolyFill(dxf, line4, 0.1, contour);

                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;


                    LinearDimension dim1 = new LinearDimension(new Line(v8, v7), (v6.X - v7.X) / 2, 90, dimensionStyle);
                    dim1.UserText = "b = " + b;
                    dxf.AddEntity(dim1);

                    LinearDimension dim2 = new LinearDimension(new Line(v10, v5), e*2, 90, dimensionStyle);
                    dim2.UserText = "d2 = " + d2;
                    dxf.AddEntity(dim2);

                    LinearDimension dim3 = new LinearDimension(new Line(v18, v19), offset, 90, dimensionStyle);
                    dim3.UserText = "D = " + D;
                    dxf.AddEntity(dim3);

                    LinearDimension dim4 = new LinearDimension(new Line(v4, v11), (v16.X - v18.X)+e, -90, dimensionStyle);
                    dim4.UserText = "D1 = " + D1;
                    dxf.AddEntity(dim4);

                    LinearDimension dim5 = new LinearDimension(new Line(v20, v9), e, 180, dimensionStyle);
                    dim5.UserText = "e = " + e;
                    dxf.AddEntity(dim5);

                    LinearDimension dim6 = new LinearDimension(new Line(v20, v19), e*1.5, 180, dimensionStyle);
                    dim6.UserText = "e = " + e;
                    dxf.AddEntity(dim6);

                    LinearDimension dim7 = new LinearDimension(new Line(v11, v19), e*1.5+(v11.Y +v19.Y)/2- (v20.Y + v19.Y) / 2, 180, dimensionStyle);
                    dim7.UserText = "a = " + a;
                    dxf.AddEntity(dim7);

                    RadialDimension dimrad1 = new RadialDimension(arc3, 45, offset, dimensionStyle);
                    dimrad1.UserText = "R = " + R;
                    dxf.AddEntity(dimrad1);




                }
                if (bbxs == 1)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + i * 1.308 + 4, v1.Y);
                    Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + d4 / 2);
                    Vector2 v5 = new Vector2(v4.X + (l1 - (D - d) / tg), v4.Y);
                    Vector2 v6 = new Vector2(v5.X, v3.Y + d / 2);
                    Vector2 v7 = new Vector2(v5.X + (D - d) / tg, v3.Y + D / 2);
                    Vector2 v8 = new Vector2(v7.X + a, v3.Y + D1 / 2);
                    Vector2 v9 = new Vector2(v8.X, v8.Y * -1);
                    Vector2 v10 = new Vector2(v7.X, v7.Y * -1);
                    Vector2 v11 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v12 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v13 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v14 = new Vector2(v8.X + l2 / 15.188, v3.Y + D1 / 2.622);
                    Vector2 v15 = new Vector2(v14.X + l2 / 18.225, v14.Y);
                    Vector2 v18 = new Vector2(v15.X, v15.Y * -1);
                    Vector2 v19 = new Vector2(v14.X, v14.Y * -1);
                    Vector2 v16 = new Vector2(v15.X, v15.Y - (v15.Y - v18.Y) / 3);
                    Vector2 v17 = new Vector2(v16.X, v16.Y * -1);
                    Vector2 v31 = new Vector2(v3.X, v3.Y + d10 / 2);
                    Vector2 v32 = new Vector2(v31.X + (d10 - d9) / 2 / Math.Tan(60 * pi / 180), v3.Y + d9 / 2);
                    Vector2 v20 = new Vector2(v32.X + (d9 - d8) / 2 / Math.Tan(30 * pi / 180), v3.Y + d8 / 2);
                    Vector2 v21 = new Vector2(v3.X + l11, v20.Y);
                    Vector2 v22 = new Vector2(v21.X + (d8 - d8 / 1.32) / 2, v21.Y - (d8 - d8 / 1.32) / 2);
                    Vector2 v23 = new Vector2(v3.X + i * 1.154, v22.Y);
                    Vector2 v24 = new Vector2(v23.X + (v23.Y - v3.Y), v3.Y);
                    Vector2 v25 = new Vector2(v23.X, v23.Y * -1);
                    Vector2 v26 = new Vector2(v22.X, v22.Y * -1);
                    Vector2 v27 = new Vector2(v21.X, v21.Y * -1);
                    Vector2 v28 = new Vector2(v20.X, v20.Y * -1);
                    Vector2 v29 = new Vector2(v32.X, v32.Y * -1);
                    Vector2 v30 = new Vector2(v31.X, v31.Y * -1);
                    Vector2 v33 = new Vector2(v21.X, v3.Y + d1 / 2);
                    Vector2 v34 = new Vector2(v33.X, v33.Y * -1);
                    Vector2 v35 = new Vector2(v3.X + i, v23.Y);
                    Vector2 v36 = new Vector2(v35.X, v35.Y * -1);

                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    LwPolyline line2 = new LwPolyline();
                    line2.Vertexes.Add(new LwPolylineVertex(v12));
                    line2.Vertexes.Add(new LwPolylineVertex(v5));
                    line2.Vertexes.Add(new LwPolylineVertex(v4));
                    line2.Vertexes.Add(new LwPolylineVertex(v13));
                    line2.Vertexes.Add(new LwPolylineVertex(v12));
                    line2.Vertexes.Add(new LwPolylineVertex(v11));
                    line2.Vertexes.Add(new LwPolylineVertex(v10));
                    line2.Vertexes.Add(new LwPolylineVertex(v9));
                    line2.Vertexes.Add(new LwPolylineVertex(v8));
                    line2.Vertexes.Add(new LwPolylineVertex(v7));
                    line2.Vertexes.Add(new LwPolylineVertex(v6));
                    line2.Vertexes.Add(new LwPolylineVertex(v5));
                    fun.PolyFill(dxf, line2, 0.1, contour);

                    LwPolyline line3 = new LwPolyline();
                    line3.Vertexes.Add(new LwPolylineVertex(v8));
                    line3.Vertexes.Add(new LwPolylineVertex(v14));
                    line3.Vertexes.Add(new LwPolylineVertex(v15));
                    line3.Vertexes.Add(new LwPolylineVertex(v16));
                    line3.Vertexes.Add(new LwPolylineVertex(v17));
                    line3.Vertexes.Add(new LwPolylineVertex(v18));
                    line3.Vertexes.Add(new LwPolylineVertex(v19));
                    line3.Vertexes.Add(new LwPolylineVertex(v9));
                    line3.Vertexes[0].Bulge = Math.Tan(44 * pi / 180 / 4);
                    line3.Vertexes[2].Bulge = Math.Tan(-44 * pi / 180 / 4);
                    line3.Vertexes[3].Bulge = Math.Tan(44 * pi / 180 / 4);
                    line3.Vertexes[4].Bulge = Math.Tan(-44 * pi / 180 / 4);
                    line3.Vertexes[6].Bulge = Math.Tan(44 * pi / 180 / 4);
                    fun.PolyFill(dxf, line3, 0.1, contour);

                    if (d10 != 0)
                    {
                        Line line5 = new Line(v31, v32);
                        line5.Layer = refin;
                        line5.Linetype = Linetype.Dashed;
                        line5.LinetypeScale = 5;
                        dxf.AddEntity(line5);

                        Line line6 = new Line(v20, v32);
                        line6.Layer = refin;
                        line6.Linetype = Linetype.Dashed;
                        line6.LinetypeScale = 5;
                        dxf.AddEntity(line6);

                        Line line7 = new Line(v20, v21);
                        line7.Layer = refin;
                        line7.Linetype = Linetype.Dashed;
                        line7.LinetypeScale = 5;
                        dxf.AddEntity(line7);

                        Line line8 = new Line(v22, v33);
                        line8.Layer = refin;
                        line8.Linetype = Linetype.Dashed;
                        line8.LinetypeScale = 5;
                        dxf.AddEntity(line8);

                        Line line9 = new Line(v23, v22);
                        line9.Layer = refin;
                        line9.Linetype = Linetype.Dashed;
                        line9.LinetypeScale = 5;
                        dxf.AddEntity(line9);

                        Line line10 = new Line(v23, v24);
                        line10.Layer = refin;
                        line10.Linetype = Linetype.Dashed;
                        line10.LinetypeScale = 5;
                        dxf.AddEntity(line10);

                        Line line11 = new Line(v24, v25);
                        line11.Layer = refin;
                        line11.Linetype = Linetype.Dashed;
                        line11.LinetypeScale = 5;
                        dxf.AddEntity(line11);

                        Line line12 = new Line(v25, v26);
                        line12.Layer = refin;
                        line12.Linetype = Linetype.Dashed;
                        line12.LinetypeScale = 5;
                        dxf.AddEntity(line12);

                        Line line13 = new Line(v26, v34);
                        line13.Layer = refin;
                        line13.Linetype = Linetype.Dashed;
                        line13.LinetypeScale = 5;
                        dxf.AddEntity(line13);

                        Line line14 = new Line(v27, v28);
                        line14.Layer = refin;
                        line14.Linetype = Linetype.Dashed;
                        line14.LinetypeScale = 5;
                        dxf.AddEntity(line14);

                        Line line15 = new Line(v28, v29);
                        line15.Layer = refin;
                        line15.Linetype = Linetype.Dashed;
                        line15.LinetypeScale = 5;
                        dxf.AddEntity(line15);

                        Line line16 = new Line(v29, v30);
                        line16.Layer = refin;
                        line16.Linetype = Linetype.Dashed;
                        line16.LinetypeScale = 5;
                        dxf.AddEntity(line16);

                        Line line17 = new Line(v32, v29);
                        line17.Layer = refin;
                        line17.Linetype = Linetype.Dashed;
                        line17.LinetypeScale = 5;
                        dxf.AddEntity(line17);

                        Line line18 = new Line(v20, v28);
                        line18.Layer = refin;
                        line18.Linetype = Linetype.Dashed;
                        line18.LinetypeScale = 5;
                        dxf.AddEntity(line18);

                        Line line19 = new Line(v21, v27);
                        line19.Layer = refin;
                        line19.Linetype = Linetype.Dashed;
                        line19.LinetypeScale = 5;
                        dxf.AddEntity(line19);

                        Line line20 = new Line(v22, v26);
                        line20.Layer = refin;
                        line20.Linetype = Linetype.Dashed;
                        line20.LinetypeScale = 5;
                        dxf.AddEntity(line20);

                        Line line21 = new Line(v23, v25);
                        line21.Layer = refin;
                        line21.Linetype = Linetype.Dashed;
                        line21.LinetypeScale = 5;
                        dxf.AddEntity(line21);

                        Line line22 = new Line(v35, v36);
                        line22.Layer = refin;
                        line22.Linetype = Linetype.Dashed;
                        line22.LinetypeScale = 5;
                        dxf.AddEntity(line22);

                    }


                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;


                    LinearDimension dim1 = new LinearDimension(new Line(v6, v11), i / 2, 90, dimensionStyle);
                    dim1.UserText = "d = " + d;
                    dxf.AddEntity(dim1);

                    LinearDimension dim2 = new LinearDimension(new Line(v13, v36), d, 180, dimensionStyle);
                    dim2.UserText = "i = " + i;
                    dxf.AddEntity(dim2);

                    LinearDimension dim3 = new LinearDimension(new Line(v7, v10), i / 2.5, 90, dimensionStyle);
                    dim3.UserText = "D = " + D;
                    dxf.AddEntity(dim3);

                    LinearDimension dim4 = new LinearDimension(new Line(v8, v9), (v15.X - v8.X) + i / 2, -90, dimensionStyle);
                    dim4.UserText = "D1 = " + D1;
                    dxf.AddEntity(dim4);

                    LinearDimension dim5 = new LinearDimension(new Line(v13, v10), i, 180, dimensionStyle);
                    dim5.UserText = "l1 = " + l1;
                    dxf.AddEntity(dim5);

                    LinearDimension dim6 = new LinearDimension(new Line(v10, v9), i + (v10.Y + v9.Y) / 2 - (v13.Y + v10.Y) / 2, 180, dimensionStyle);
                    dim6.UserText = "a = " + a;
                    dxf.AddEntity(dim6);

                    LinearDimension dim7 = new LinearDimension(new Line(v13, v9), i * 1.5, 180, dimensionStyle);
                    dim7.UserText = "l2 = " + l2;
                    dxf.AddEntity(dim7);

                    LinearDimension dim8 = new LinearDimension(new Line(v5, v12), i * 2, -90, dimensionStyle);
                    dim8.UserText = "d4 = " + d4;
                    dxf.AddEntity(dim8);

                    if (d10 != 0)
                    {
                        LinearDimension dim9 = new LinearDimension(new Line(v33, v34), i * 1.5, -90, dimensionStyle);
                        dim9.UserText = "d1 = " + d1;
                        dxf.AddEntity(dim9);

                    }




                }
                if (bbxs == 2)
                {
                    if (l3 == 0)
                    {
                        l3 = e + (D - d2) / tg;
                    }
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l3 * 1.5 + 4, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - 2 - l3 / 6, v1.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D1 / 2);
                    Vector2 v22 = new Vector2(v3.X - a, v3.Y + D / 2);
                    Vector2 v5 = new Vector2(v22.X - l7, v3.Y + D / 2 - (l7 * tg) / 2);
                    Vector2 v6 = new Vector2(v5.X - (D - d2) / 2, v3.Y + d2 / 2);
                    Vector2 v7 = new Vector2(v22.X - l12 + p / 2, v6.Y);
                    Vector2 v8 = new Vector2(v7.X - p, v7.Y);
                    Vector2 v10 = new Vector2(v22.X - l8, v3.Y + D / 2 - (l8 * tg) / 2);
                    Vector2 v9 = new Vector2(v10.X + (v10.Y - d2 / 2), v8.Y);
                    Vector2 v11 = new Vector2(v22.X - (D - d2) / tg, v3.Y + d2 / 2);
                    if (l7 == 0)
                    {
                        v11 = new Vector2(v22.X - (D-d2)/tg, v3.Y + d2 / 2);
                    }
                    Vector2 v12 = new Vector2(v11.X - (d2 - b) / 2, v3.Y + b / 2);
                    Vector2 v13 = new Vector2(v11.X - e / 1.14, v12.Y);
                    Vector2 v24 = new Vector2(v11.X - e, v3.Y);
                    Vector2 v14 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v23 = new Vector2(v22.X, v22.Y * -1);
                    Vector2 v15 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v16 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v17 = new Vector2(v9.X, v9.Y * -1);
                    Vector2 v18 = new Vector2(v10.X, v10.Y * -1);
                    Vector2 v19 = new Vector2(v11.X, v11.Y * -1);
                    Vector2 v20 = new Vector2(v12.X, v12.Y * -1);
                    Vector2 v21 = new Vector2(v13.X, v13.Y * -1);
                    Vector2 v25 = new Vector2(v7.X, v7.Y - D1 / 2.92);
                    Vector2 v26 = new Vector2(v8.X, v25.Y);
                    Vector2 v27 = new Vector2(v6.X - (v6.X - v7.X) / 3, v6.Y);
                    Vector2 v28 = new Vector2(v27.X, v27.Y - D1 / 1.825);
                    Vector2 v29 = new Vector2(v9.X + (v8.X - v9.X) / 3, v9.Y);
                    Vector2 v30 = new Vector2(v29.X, v28.Y);
                    Vector2 v31 = new Vector2(v7.X - p / 2, v4.Y);
                    Vector2 v32 = new Vector2(v31.X, v16.Y + (v28.Y - v16.Y) / 2);
                    Vector2 v33 = new Vector2(v13.X, v3.Y + b / 4);
                    Vector2 v34 = new Vector2(v3.X + l3 / 9.7, v33.Y);
                    Vector2 v35 = new Vector2(v33.X, v33.Y * -1);
                    Vector2 v36 = new Vector2(v34.X, v34.Y * -1);
                    Vector2 v37 = new Vector2(v33.X + e / 2.785, v33.Y);
                    Vector2 v38 = new Vector2(v37.X, v35.Y);
                    Vector2 v39 = new Vector2(v4.X + l3 / 31.43, v3.Y + D1 / 2.308);
                    Vector2 v40 = new Vector2(v34.X, v39.Y);
                    Vector2 v41 = new Vector2(v39.X, v39.Y * -1);
                    Vector2 v42 = new Vector2(v40.X, v41.Y);
                   

                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    if (l12 != 0)
                    {
                        LwPolyline line2 = new LwPolyline();
                        line2.Vertexes.Add(new LwPolylineVertex(v5));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        line2.Vertexes.Add(new LwPolylineVertex(v23));
                        line2.Vertexes.Add(new LwPolylineVertex(v14));
                        line2.Vertexes.Add(new LwPolylineVertex(v4));
                        line2.Vertexes.Add(new LwPolylineVertex(v22));
                        line2.Vertexes.Add(new LwPolylineVertex(v5));
                        line2.Vertexes.Add(new LwPolylineVertex(v6));
                        line2.Vertexes.Add(new LwPolylineVertex(v16));
                        line2.Vertexes.Add(new LwPolylineVertex(v15));
                        fun.PolyFill(dxf, line2, 0.1, contour);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v8));
                        line3.Vertexes.Add(new LwPolylineVertex(v9));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes[1].Bulge = Math.Tan(-144 * pi / 180 / 4);
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line6 = new LwPolyline();
                        line6.Vertexes.Add(new LwPolylineVertex(v7));
                        line6.Vertexes.Add(new LwPolylineVertex(v25));
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes.Add(new LwPolylineVertex(v8));
                        line6.Vertexes.Add(new LwPolylineVertex(v29));
                        line6.Vertexes.Add(new LwPolylineVertex(v30));
                        line6.Vertexes.Add(new LwPolylineVertex(v28));
                        line6.Vertexes.Add(new LwPolylineVertex(v27));
                        line6.Vertexes[1].Bulge = Math.Tan(-144 * pi / 180 / 4);
                        line6.Vertexes[5].Bulge = Math.Tan(105 * pi / 180 / 4);
                        fun.PolyFill(dxf, line6, 0.1, contour);

                        Line line7 = new Line(v31, v32);
                        line7.Layer = centre;
                        line7.Linetype = Linetype.DashDot;
                        line7.LinetypeScale = 3;
                        dxf.AddEntity(line7);


                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v18));
                        line4.Vertexes.Add(new LwPolylineVertex(v17));
                        line4.Vertexes.Add(new LwPolylineVertex(v9));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v18));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        fun.PolyFill(dxf, line4, 0.1, contour);
                    }
                    if (l12 == 0)
                    {
                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v11));
                        line4.Vertexes.Add(new LwPolylineVertex(v22));
                        line4.Vertexes.Add(new LwPolylineVertex(v4));
                        line4.Vertexes.Add(new LwPolylineVertex(v14));
                        line4.Vertexes.Add(new LwPolylineVertex(v23));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        fun.PolyFill(dxf, line4, 0.1, contour);
                    }
                    LwPolyline line5 = new LwPolyline();
                    line5.Vertexes.Add(new LwPolylineVertex(v13));
                    line5.Vertexes.Add(new LwPolylineVertex(v12));
                    line5.Vertexes.Add(new LwPolylineVertex(v20));
                    line5.Vertexes.Add(new LwPolylineVertex(v21));
                    fun.PolyFill(dxf, line5, 0.1, contour);

                    LwPolyline line8 = new LwPolyline();
                    line8.Vertexes.Add(new LwPolylineVertex(v4));
                    line8.Vertexes.Add(new LwPolylineVertex(v39));
                    line8.Vertexes.Add(new LwPolylineVertex(v40));
                    line8.Vertexes.Add(new LwPolylineVertex(v34));
                    line8.Vertexes.Add(new LwPolylineVertex(v36));
                    line8.Vertexes.Add(new LwPolylineVertex(v42));
                    line8.Vertexes.Add(new LwPolylineVertex(v41));
                    line8.Vertexes.Add(new LwPolylineVertex(v14));
                    line8.Vertexes[0].Bulge = Math.Tan(45 * pi / 180 / 4);
                    line8.Vertexes[2].Bulge = Math.Tan(-72 * pi / 180 / 4);
                    line8.Vertexes[3].Bulge = Math.Tan(62 * pi / 180 / 4);
                    line8.Vertexes[4].Bulge = Math.Tan(-72 * pi / 180 / 4);
                    line8.Vertexes[6].Bulge = Math.Tan(45 * pi / 180 / 4);
                    fun.PolyFill(dxf, line8, 0.1, contour);

                    Line line9 = new Line(v33, v34);
                    line9.Layer = refin ;
                    line9.Linetype = Linetype.Dashed;
                    line9.LinetypeScale = 3;
                    dxf.AddEntity(line9);

                    Line line10 = new Line(v33, v35);
                    line10.Layer = refin;
                    line10.Linetype = Linetype.Dashed;
                    line10.LinetypeScale = 3;
                    dxf.AddEntity(line10);

                    Line line11 = new Line(v36, v35);
                    line11.Layer = refin;
                    line11.Linetype = Linetype.Dashed;
                    line11.LinetypeScale = 3;
                    dxf.AddEntity(line11);

                    Line line12 = new Line(v37, v38);
                    line12.Layer = refin;
                    line12.Linetype = Linetype.Dashed;
                    line12.LinetypeScale = 3;
                    dxf.AddEntity(line12);

                    Arc arc1 = fun.DrawArc3(v13, v24, v21);
                    fun.drawBArc(dxf, arc1, 0.1, contour);

                    Arc arc2 = fun.DrawArc4(v12, R, v11, 0);
                    fun.drawBArc(dxf, arc2, 0.1, contour);

                    Arc arc3 = fun.DrawArc4(v19, R, v20, 0);
                    fun.drawBArc(dxf, arc3, 0.1, contour);

                    //填充
                    if (l12 != 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v7));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v27));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v28));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v30));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v29));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes[0].Bulge = Math.Tan(144 * pi / 180 / 4);
                        hatchpoly1.Vertexes[4].Bulge = Math.Tan(-105 * pi / 180 / 4);
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);
                    }
                    LwPolyline hatchpoly2 = new LwPolyline();
                    hatchpoly2.Vertexes.Add(new LwPolylineVertex(v33));
                    hatchpoly2.Vertexes.Add(new LwPolylineVertex(v37));
                    hatchpoly2.Vertexes.Add(new LwPolylineVertex(v38));
                    hatchpoly2.Vertexes.Add(new LwPolylineVertex(v35));
                    hatchpoly2.Vertexes.Add(new LwPolylineVertex(v33));
                    hatchpoly2.IsClosed = true;
                    String[] htype2 = new String[100];
                    Line[] hline2 = new Line[100];
                    Arc[] harc2 = new Arc[100];
                    int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                    for (int I = 0; I < hnumst2; I++)
                    {
                        htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype2[I] == "Line")
                        {
                            hline2[I] = (Line)hatchpoly2.Explode()[I];
                        }
                        if (htype2[I] == "Arc")
                        {
                            harc2[I] = (Arc)hatchpoly2.Explode()[I];
                        }
                    }
                    fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);


                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;

                    if (l12 !=0)
                    { 
                    LinearDimension dim1 = new LinearDimension(new Line(v7, v8), p, 0, dimensionStyle);
                    dim1.UserText = "P = " + p;
                    dxf.AddEntity(dim1);

                    LinearDimension dim2 = new LinearDimension(new Line(v32, v23), D1/2+(v32.Y +v23.Y )/2-(v24.Y +v19.Y )/2 , 180, dimensionStyle);
                    dim2.UserText = "l12 = " + l12;
                    dxf.AddEntity(dim2);

                    LinearDimension dim6 = new LinearDimension(new Line(v5, v22), D1 / 2, 0, dimensionStyle);
                    dim6.UserText = "l7 = " + l7;
                    dxf.AddEntity(dim6);

                    LinearDimension dim7 = new LinearDimension(new Line(v10, v22), D1, 0, dimensionStyle);
                    dim7.UserText = "l8 = " + l8;
                    dxf.AddEntity(dim7);

                    }
                    LinearDimension dim3 = new LinearDimension(new Line(v24, v19), D1/2, 180, dimensionStyle);
                    dim3.UserText = "e = " + e;
                    dxf.AddEntity(dim3);

                    LinearDimension dim4 = new LinearDimension(new Line(v24, v23), D1, 180, dimensionStyle);
                    dim4.UserText = "l3";
                    dxf.AddEntity(dim4);

                    LinearDimension dim5 = new LinearDimension(new Line(v14, v23), D1+(v14.Y +v23.Y )/2-(v24.Y +v23.Y )/2, 180, dimensionStyle);
                    dim5.UserText = "a = " + a;
                    dxf.AddEntity(dim5);

                    LinearDimension dim8 = new LinearDimension(new Line(v13, v21), b, 90, dimensionStyle);
                    dim8.UserText = "b = " + b;
                    dxf.AddEntity(dim8);

                    LinearDimension dim9 = new LinearDimension(new Line(v11, v19), D1*2, 90, dimensionStyle);
                    dim9.UserText = "d2 = " + d2;
                    dxf.AddEntity(dim9);

                    LinearDimension dim10 = new LinearDimension(new Line(v22, v23), 0, 90, dimensionStyle);
                    dim10.UserText = "D = " + D;
                    dxf.AddEntity(dim10);

                    LinearDimension dim11 = new LinearDimension(new Line(v4, v14), l3/5, -90, dimensionStyle);
                    dim11.UserText = "D1 = " + D1;
                    dxf.AddEntity(dim11);


                }
                if (bbxs == 3)
                {
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(v1.X + l2 * 1.2 + 4, v1.Y);
                    Vector2 v3 = new Vector2(v2.X - l2 / 7.08 - 2, v2.Y);
                    Vector2 v4 = new Vector2(v3.X, v3.Y + D1 / 2);
                    Vector2 v5 = new Vector2(v4.X - a, v3.Y + D / 2);
                    Vector2 v6 = new Vector2(v5.X - l7, v3.Y + D / 2 - (l7 * tg) / 2);
                    Vector2 v7 = new Vector2(v6.X - (v6.Y - D2 / 2), v3.Y + D2 / 2);
                    Vector2 v8 = new Vector2(v5.X - l12 + p / 2, v7.Y);
                    Vector2 v9 = new Vector2(v8.X - p, v8.Y);
                    Vector2 v11 = new Vector2(v5.X - l8, v3.Y + D / 2 - (l8 * tg) / 2);
                    Vector2 v10 = new Vector2(v11.X + (v11.Y - D2 / 2), v9.Y);
                    Vector2 v12 = new Vector2(v5.X - (D - d) / tg, v3.Y + d / 2);
                    Vector2 v13 = new Vector2(v12.X - (d-d4)/2, v3.Y + d4 / 2);
                    if (d4 > d)
                    {
                        v13 = new Vector2(v12.X + (d - d4) / 2, v3.Y + d4 / 2);
                    }
                    Vector2 v14 = new Vector2(v13.X - t, v13.Y);
                    Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
                    Vector2 v16 = new Vector2(v5.X, v5.Y * -1);
                    Vector2 v17 = new Vector2(v6.X, v6.Y * -1);
                    Vector2 v18 = new Vector2(v7.X, v7.Y * -1);
                    Vector2 v19 = new Vector2(v10.X, v10.Y * -1);
                    Vector2 v20 = new Vector2(v11.X, v11.Y * -1);
                    Vector2 v21 = new Vector2(v12.X, v12.Y * -1);
                    Vector2 v22 = new Vector2(v13.X, v13.Y * -1);
                    Vector2 v23 = new Vector2(v14.X, v14.Y * -1);
                    Vector2 v24 = new Vector2(v5.X - l12, v4.Y);
                    Vector2 v25 = new Vector2(v24.X, v24.Y - D1 / 1.398);
                    Vector2 v26 = new Vector2(v8.X, v3.Y + (d8 / 1.586) / 2);
                    Vector2 v27 = new Vector2(v24.X, v3.Y);
                    Vector2 v28 = new Vector2(v9.X, v26.Y);
                    Vector2 v29 = new Vector2(v7.X - (v7.X - v8.X) / 2, v7.Y);
                    Vector2 v30 = new Vector2(v29.X, v26.Y);
                    Vector2 v31 = new Vector2(v26.X, v26.Y * -1);
                    Vector2 v34 = new Vector2(v9.X - (v9.X - v10.X) * 3 / 5, v9.Y);
                    Vector2 v33 = new Vector2(v9.X - (v9.X - v10.X) / 2, v28.Y);
                    Vector2 v32 = new Vector2(v28.X - (v28.X - v33.X) / 2, v31.Y);
                    Vector2 v35 = new Vector2(v14.X, v3.Y + d10 / 2);
                    Vector2 v36 = new Vector2(v35.X + (d10 - d9) / 2 / Math.Tan(60 * pi / 180), v3.Y + d9 / 2);
                    Vector2 v37 = new Vector2(v36.X + (d9 - d8) / 2 / Math.Tan(30 * pi / 180), v3.Y + d8 / 2);
                    Vector2 v38 = new Vector2(v35.X + l11, v37.Y);
                    Vector2 v39 = new Vector2(v38.X + (v38.Y - v26.Y), v26.Y);
                    Vector2 v40 = new Vector2(v35.X + i, v39.Y);
                    Vector2 v41 = new Vector2(v35.X, v35.Y * -1);
                    Vector2 v42 = new Vector2(v36.X, v36.Y * -1);
                    Vector2 v43 = new Vector2(v37.X, v37.Y * -1);
                    Vector2 v44 = new Vector2(v38.X, v38.Y * -1);
                    Vector2 v45 = new Vector2(v39.X, v39.Y * -1);
                    Vector2 v46 = new Vector2(v40.X, v40.Y * -1);
                    Vector2 v47 = new Vector2(v40.X + l2 / 19.957, v40.Y);
                    Vector2 v49 = new Vector2(v47.X - (v47.X - v40.X) / 4, v3.Y + D / 2 - (v5.X - v47.X - (v47.X - v40.X) / 4) * tg / 2);
                    Vector2 v48 = new Vector2(v49.X, v49.Y - (v49.Y - v47.Y) / 2);
                    Vector2 v50 = new Vector2(v47.X, v46.Y);
                    Vector2 v51 = new Vector2(v48.X, v48.Y * -1);
                    Vector2 v52 = new Vector2(v49.X, v49.Y * -1);
                    Vector2 v53 = new Vector2(v4.X + (D1 - D1 / 1.244) / 2, v3.Y + (D1 / 1.244) / 2);
                    Vector2 v54 = new Vector2(v4.X + l2 / 7.08, v53.Y);
                    Vector2 v55 = new Vector2(v54.X, v47.Y);
                    Vector2 v56 = new Vector2(v55.X, v55.Y * -1);
                    Vector2 v57 = new Vector2(v54.X, v54.Y * -1);
                    Vector2 v58 = new Vector2(v53.X, v53.Y * -1);
                    Vector2 v59 = new Vector2(0,0);
                    Vector2 v60 = new Vector2(0,0);
                    if (d10 == 0)
                    {
                        v55 = new Vector2(v54.X, v3.Y + (v54.Y - v57.Y) / 3);
                        v56 = new Vector2(v55.X, v55.Y * -1);
                        v59 = new Vector2(v14.X, v55.Y);
                        v60 = new Vector2(v59.X, v59.Y * -1);
                    }


                    //
                    Line line1 = new Line(v1, v2);
                    line1.Layer = centre;
                    line1.Linetype = Linetype.DashDot;
                    line1.LinetypeScale = 3;
                    dxf.AddEntity(line1);

                    if (p != 0)
                    {
                        Line line2 = new Line(v24, v25);
                        line2.Layer = centre;
                        line2.Linetype = Linetype.DashDot;
                        line2.LinetypeScale = 3;
                        dxf.AddEntity(line2);

                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v15));
                        line3.Vertexes.Add(new LwPolylineVertex(v4));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v6));
                        line3.Vertexes.Add(new LwPolylineVertex(v7));
                        line3.Vertexes.Add(new LwPolylineVertex(v18));
                        line3.Vertexes.Add(new LwPolylineVertex(v17));
                        fun.PolyFill(dxf, line3, 0.1, contour);

                        LwPolyline line4 = new LwPolyline();
                        line4.Vertexes.Add(new LwPolylineVertex(v7));
                        line4.Vertexes.Add(new LwPolylineVertex(v8));
                        line4.Vertexes.Add(new LwPolylineVertex(v9));
                        line4.Vertexes.Add(new LwPolylineVertex(v10));
                        line4.Vertexes.Add(new LwPolylineVertex(v19));
                        line4.Vertexes.Add(new LwPolylineVertex(v18));
                        line4.Vertexes[1].Bulge = Math.Tan(-41 * pi / 180 / 4);
                        fun.PolyFill(dxf, line4, 0.1, contour);

                        LwPolyline line5 = new LwPolyline();
                        line5.Vertexes.Add(new LwPolylineVertex(v11));
                        line5.Vertexes.Add(new LwPolylineVertex(v20));
                        line5.Vertexes.Add(new LwPolylineVertex(v19));
                        line5.Vertexes.Add(new LwPolylineVertex(v10));
                        line5.Vertexes.Add(new LwPolylineVertex(v11));
                        line5.Vertexes.Add(new LwPolylineVertex(v12));
                        line5.Vertexes.Add(new LwPolylineVertex(v13));
                        line5.Vertexes.Add(new LwPolylineVertex(v14));
                        line5.Vertexes.Add(new LwPolylineVertex(v23));
                        line5.Vertexes.Add(new LwPolylineVertex(v22));
                        line5.Vertexes.Add(new LwPolylineVertex(v21));
                        line5.Vertexes.Add(new LwPolylineVertex(v20));
                        fun.PolyFill(dxf, line5, 0.1, contour);

                        LwPolyline line6 = new LwPolyline();
                        line6.Vertexes.Add(new LwPolylineVertex(v9));
                        line6.Vertexes.Add(new LwPolylineVertex(v28));
                        line6.Vertexes.Add(new LwPolylineVertex(v33));
                        line6.Vertexes.Add(new LwPolylineVertex(v28));
                        line6.Vertexes.Add(new LwPolylineVertex(v27));
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes.Add(new LwPolylineVertex(v8));
                        line6.Vertexes.Add(new LwPolylineVertex(v26));
                        line6.Vertexes.Add(new LwPolylineVertex(v30));
                        fun.PolyFill(dxf, line6, 0.1, contour);

                        LwPolyline line7 = new LwPolyline();
                        line7.Vertexes.Add(new LwPolylineVertex(v31));
                        line7.Vertexes.Add(new LwPolylineVertex(v32));
                        line7.Vertexes.Add(new LwPolylineVertex(v31));
                        line7.Vertexes[1].Bulge = Math.Tan(120 * pi / 180 / 4);
                        fun.PolyFill(dxf, line7, 0.1, contour);

                        LwPolyline line10 = new LwPolyline();
                        line10.Vertexes.Add(new LwPolylineVertex(v29));
                        line10.Vertexes.Add(new LwPolylineVertex(v30));
                        line10.Vertexes.Add(new LwPolylineVertex(v31));
                        line10.Vertexes.Add(new LwPolylineVertex(v32));
                        line10.Vertexes.Add(new LwPolylineVertex(v33));
                        line10.Vertexes.Add(new LwPolylineVertex(v34));
                        line10.Vertexes[0].Bulge = Math.Tan(-15 * pi / 180 / 4);
                        line10.Vertexes[1].Bulge = Math.Tan(-10 * pi / 180 / 4);
                        line10.Vertexes[3].Bulge = Math.Tan(-1 * pi / 180 / 4);
                        line10.Vertexes[4].Bulge = Math.Tan(-2 * pi / 180 / 4);
                        fun.PolyFill(dxf, line10, 0.1, contour);

                        Line line12 = new Line(v47, v33);
                        line12.Layer = refin;
                        line12.Linetype = Linetype.Dashed;
                        line12.LinetypeScale = 3;
                        dxf.AddEntity(line12);

                        Line line13 = new Line(v50, v32);
                        line13.Layer = refin;
                        line13.Linetype = Linetype.Dashed;
                        line13.LinetypeScale = 3;
                        dxf.AddEntity(line13);

                        Line line14 = new Line(v30, v55);
                        line14.Layer = refin;
                        line14.Linetype = Linetype.Dashed;
                        line14.LinetypeScale = 3;
                        dxf.AddEntity(line14);

                        Line line15 = new Line(v56, v31);
                        line15.Layer = refin;
                        line15.Linetype = Linetype.Dashed;
                        line15.LinetypeScale = 3;
                        dxf.AddEntity(line15);


                    }
                    if (p == 0)
                    {
                        LwPolyline line3 = new LwPolyline();
                        line3.Vertexes.Add(new LwPolylineVertex(v4));
                        line3.Vertexes.Add(new LwPolylineVertex(v5));
                        line3.Vertexes.Add(new LwPolylineVertex(v12));
                        line3.Vertexes.Add(new LwPolylineVertex(v13));
                        line3.Vertexes.Add(new LwPolylineVertex(v14));
                        line3.Vertexes.Add(new LwPolylineVertex(v23));
                        line3.Vertexes.Add(new LwPolylineVertex(v22));
                        line3.Vertexes.Add(new LwPolylineVertex(v21));
                        line3.Vertexes.Add(new LwPolylineVertex(v16));
                        line3.Vertexes.Add(new LwPolylineVertex(v15));
                        line3.Vertexes.Add(new LwPolylineVertex(v4));
                        fun.PolyFill(dxf, line3, 0.1, contour);

                    }

                    if (d10 != 0)
                    {
                        LwPolyline line9 = new LwPolyline();
                        line9.Vertexes.Add(new LwPolylineVertex(v35));
                        line9.Vertexes.Add(new LwPolylineVertex(v36));
                        line9.Vertexes.Add(new LwPolylineVertex(v37));
                        line9.Vertexes.Add(new LwPolylineVertex(v38));
                        line9.Vertexes.Add(new LwPolylineVertex(v39));
                        line9.Vertexes.Add(new LwPolylineVertex(v47));
                        line9.Vertexes.Add(new LwPolylineVertex(v40));
                        line9.Vertexes.Add(new LwPolylineVertex(v46));
                        line9.Vertexes.Add(new LwPolylineVertex(v50));
                        line9.Vertexes.Add(new LwPolylineVertex(v45));
                        line9.Vertexes.Add(new LwPolylineVertex(v44));
                        line9.Vertexes.Add(new LwPolylineVertex(v43));
                        line9.Vertexes.Add(new LwPolylineVertex(v42));
                        line9.Vertexes.Add(new LwPolylineVertex(v41));
                        line9.Vertexes.Add(new LwPolylineVertex(v42));
                        line9.Vertexes.Add(new LwPolylineVertex(v36));
                        line9.Vertexes.Add(new LwPolylineVertex(v37));
                        line9.Vertexes.Add(new LwPolylineVertex(v43));
                        line9.Vertexes.Add(new LwPolylineVertex(v44));
                        line9.Vertexes.Add(new LwPolylineVertex(v38));
                        line9.Vertexes.Add(new LwPolylineVertex(v39));
                        line9.Vertexes.Add(new LwPolylineVertex(v45));
                        fun.PolyFill(dxf, line9, 0.1, contour);

                        LwPolyline line8 = new LwPolyline();
                        line8.Vertexes.Add(new LwPolylineVertex(v49));
                        line8.Vertexes.Add(new LwPolylineVertex(v48));
                        line8.Vertexes.Add(new LwPolylineVertex(v47));
                        line8.Vertexes.Add(new LwPolylineVertex(v50));
                        line8.Vertexes.Add(new LwPolylineVertex(v51));
                        line8.Vertexes.Add(new LwPolylineVertex(v52));
                        line8.Vertexes[0].Bulge = Math.Tan(-16 * pi / 180 / 4);
                        line8.Vertexes[1].Bulge = Math.Tan(36 * pi / 180 / 4);
                        line8.Vertexes[2].Bulge = Math.Tan(-47 * pi / 180 / 4);
                        line8.Vertexes[3].Bulge = Math.Tan(36 * pi / 180 / 4);
                        line8.Vertexes[4].Bulge = Math.Tan(-16 * pi / 180 / 4);
                        fun.PolyFill(dxf, line8, 0.1, contour);

                        if (p == 0)
                        {
                            Line line16 = new Line(v47, v55);
                            line16.Layer = refin;
                            line16.Linetype = Linetype.Dashed;
                            line16.LinetypeScale = 3;
                            dxf.AddEntity(line16);

                            Line line17 = new Line(v50, v56);
                            line17.Layer = refin;
                            line17.Linetype = Linetype.Dashed;
                            line17.LinetypeScale = 3;
                            dxf.AddEntity(line17);

                        }
                    }
                    if(d10==0)
                    {

                        Line line18 = new Line(v59, v55);
                        line18.Layer = refin;
                        line18.Linetype = Linetype.Dashed;
                        line18.LinetypeScale = 3;
                        dxf.AddEntity(line18);

                        Line line19 = new Line(v60, v56);
                        line19.Layer = refin;
                        line19.Linetype = Linetype.Dashed;
                        line19.LinetypeScale = 3;
                        dxf.AddEntity(line19);
                    }
                    LwPolyline line11 = new LwPolyline();
                    line11.Vertexes.Add(new LwPolylineVertex(v58));
                    line11.Vertexes.Add(new LwPolylineVertex(v53));
                    line11.Vertexes.Add(new LwPolylineVertex(v54));
                    line11.Vertexes.Add(new LwPolylineVertex(v55));
                    line11.Vertexes.Add(new LwPolylineVertex(v56));
                    line11.Vertexes.Add(new LwPolylineVertex(v57));
                    line11.Vertexes.Add(new LwPolylineVertex(v58));
                    line11.Vertexes.Add(new LwPolylineVertex(v15));
                    line11.Vertexes.Add(new LwPolylineVertex(v4));
                    line11.Vertexes.Add(new LwPolylineVertex(v53));
                    line11.Vertexes[2].Bulge = Math.Tan(-64 * pi / 180 / 4);
                    line11.Vertexes[3].Bulge = Math.Tan(46 * pi / 180 / 4);
                    line11.Vertexes[4].Bulge = Math.Tan(-64 * pi / 180 / 4);
                    fun.PolyFill(dxf, line11, 0.1, contour);

                    //填充
                    if (p != 0)
                    {
                        LwPolyline hatchpoly1 = new LwPolyline();
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v29));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v30));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
                        hatchpoly1.Vertexes.Add(new LwPolylineVertex(v8));
                        hatchpoly1.Vertexes[0].Bulge = Math.Tan(-15 * pi / 180 / 4);
                        hatchpoly1.IsClosed = true;
                        String[] htype1 = new String[100];
                        Line[] hline1 = new Line[100];
                        Arc[] harc1 = new Arc[100];
                        int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst1; I++)
                        {
                            htype1[I] = hatchpoly1.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype1[I] == "Line")
                            {
                                hline1[I] = (Line)hatchpoly1.Explode()[I];
                            }
                            if (htype1[I] == "Arc")
                            {
                                harc1[I] = (Arc)hatchpoly1.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);

                        LwPolyline hatchpoly2 = new LwPolyline();
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v34));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v33));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v9));
                        hatchpoly2.Vertexes.Add(new LwPolylineVertex(v10));
                        hatchpoly2.Vertexes[0].Bulge = Math.Tan(2 * pi / 180 / 4);
                        hatchpoly2.IsClosed = true;
                        String[] htype2 = new String[100];
                        Line[] hline2 = new Line[100];
                        Arc[] harc2 = new Arc[100];
                        int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst2; I++)
                        {
                            htype2[I] = hatchpoly2.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype2[I] == "Line")
                            {
                                hline2[I] = (Line)hatchpoly2.Explode()[I];
                            }
                            if (htype2[I] == "Arc")
                            {
                                harc2[I] = (Arc)hatchpoly2.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);

                        LwPolyline hatchpoly3 = new LwPolyline();
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v31));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v32));
                        hatchpoly3.Vertexes.Add(new LwPolylineVertex(v31));
                        hatchpoly3.Vertexes[1].Bulge = Math.Tan(120 * pi / 180 / 4);
                        hatchpoly3.IsClosed = true;
                        String[] htype3 = new String[100];
                        Line[] hline3 = new Line[100];
                        Arc[] harc3 = new Arc[100];
                        int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst3; I++)
                        {
                            htype3[I] = hatchpoly3.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype3[I] == "Line")
                            {
                                hline3[I] = (Line)hatchpoly3.Explode()[I];
                            }
                            if (htype3[I] == "Arc")
                            {
                                harc3[I] = (Arc)hatchpoly3.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype3, hnumst3, 45, 10, hline3, harc3, hatching);

                    }
                    if (d10 != 0)
                    {
                        LwPolyline hatchpoly4 = new LwPolyline();
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v49));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v48));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v47));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v39));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v38));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v37));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v36));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v35));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v14));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v13));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v12));
                        hatchpoly4.Vertexes.Add(new LwPolylineVertex(v49));
                        hatchpoly4.Vertexes[1].Bulge = Math.Tan(-16 * pi / 180 / 4);
                        hatchpoly4.Vertexes[1].Bulge = Math.Tan(36 * pi / 180 / 4);
                        hatchpoly4.IsClosed = true;
                        String[] htype4 = new String[100];
                        Line[] hline4 = new Line[100];
                        Arc[] harc4 = new Arc[100];
                        int hnumst4 = hatchpoly4.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst4; I++)
                        {
                            htype4[I] = hatchpoly4.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype4[I] == "Line")
                            {
                                hline4[I] = (Line)hatchpoly4.Explode()[I];
                            }
                            if (htype4[I] == "Arc")
                            {
                                harc4[I] = (Arc)hatchpoly4.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype4, hnumst4, 45, 10, hline4, harc4, hatching);

                        LwPolyline hatchpoly5 = new LwPolyline();
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v52));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v51));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v50));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v45));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v44));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v43));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v42));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v41));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v23));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v22));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v21));
                        hatchpoly5.Vertexes.Add(new LwPolylineVertex(v52));
                        hatchpoly5.Vertexes[0].Bulge = Math.Tan(16 * pi / 180 / 4);
                        hatchpoly5.Vertexes[1].Bulge = Math.Tan(-36 * pi / 180 / 4);
                        hatchpoly5.IsClosed = true;
                        String[] htype5 = new String[100];
                        Line[] hline5 = new Line[100];
                        Arc[] harc5 = new Arc[100];
                        int hnumst5 = hatchpoly5.Explode().Count;  //记录爆炸后，线段有多少
                        for (int I = 0; I < hnumst5; I++)
                        {
                            htype5[I] = hatchpoly5.Explode()[I].Type.ToString();    //将所有的元素记录成一个数组
                            if (htype5[I] == "Line")
                            {
                                hline5[I] = (Line)hatchpoly5.Explode()[I];
                            }
                            if (htype5[I] == "Arc")
                            {
                                harc5[I] = (Arc)hatchpoly5.Explode()[I];
                            }
                        }
                        fun.hatchsub1(dxf, htype5, hnumst5, 45, 10, hline5, harc5, hatching);

                    }


                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.5;
                    dimensionStyle.ExtLineExtend = 0.6;//标注延长线长度/2
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1;
                    double offset = 8;

                    if (l12 != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v9, v8), p, 0, dimensionStyle);
                        dim1.UserText = "P = " + p;
                        dxf.AddEntity(dim1);

                        LinearDimension dim2 = new LinearDimension(new Line(v15, v25), D1 / 2 - (v23.Y + v46.Y) / 2 + (v24.Y + v19.Y) / 2, 180, dimensionStyle);
                        dim2.UserText = "l12 = " + l12;
                        dxf.AddEntity(dim2);

                        LinearDimension dim6 = new LinearDimension(new Line(v5, v6), D1 / 2, 0, dimensionStyle);
                        dim6.UserText = "l7 = " + l7;
                        dxf.AddEntity(dim6);

                        LinearDimension dim7 = new LinearDimension(new Line(v5, v11), D1, 0, dimensionStyle);
                        dim7.UserText = "l8 = " + l8;
                        dxf.AddEntity(dim7);

                        LinearDimension dim9 = new LinearDimension(new Line(v7, v18), D1/2, -90, dimensionStyle);
                        dim9.UserText = "d2 = " + d2;
                        dxf.AddEntity(dim9);

                    }
                    if (d10 != 0)
                    {
                        LinearDimension dim3 = new LinearDimension(new Line(v23, v46), D1 / 2, 180, dimensionStyle);
                        dim3.UserText = "i = " + i;
                        dxf.AddEntity(dim3);
                    }
                    LinearDimension dim4 = new LinearDimension(new Line(v14, v13), D1, 0, dimensionStyle);
                    dim4.UserText = "t =" + t;
                    dxf.AddEntity(dim4);

                    LinearDimension dim8 = new LinearDimension(new Line(v5, v16), 0, 90, dimensionStyle);
                    dim8.UserText = "D =" + D;
                    dxf.AddEntity(dim8);

                    LinearDimension dim10 = new LinearDimension(new Line(v14, v23), D1/2, 90, dimensionStyle);
                    dim10.UserText = "d4 =" + d4;
                    dxf.AddEntity(dim10);

                    LinearDimension dim11 = new LinearDimension(new Line(v12, v21), D1 *1.5, 90, dimensionStyle);
                    dim11.UserText = "d =" + d;
                    dxf.AddEntity(dim11);

                    LinearDimension dim12 = new LinearDimension(new Line(v4, v15), D1*2, -90, dimensionStyle);
                    dim12.UserText = "D1 =" + D1;
                    dxf.AddEntity(dim12);

                    LinearDimension dim13 = new LinearDimension(new Line(v23, v16), D1*1.5, 180, dimensionStyle);
                    dim13.UserText = "l1 =" + l1;
                    dxf.AddEntity(dim13);

                    LinearDimension dim14 = new LinearDimension(new Line(v15, v16), D1 * 1.5+(v15.Y +v16.Y )/2-(v23.Y +v16.Y )/2, 180, dimensionStyle);
                    dim14.UserText = "a =" + a;
                    dxf.AddEntity(dim14);

                    LinearDimension dim15 = new LinearDimension(new Line(v23, v15), D1 * 2, 180, dimensionStyle);
                    dim15.UserText = "l2 =" + l2;
                    dxf.AddEntity(dim15);


                }
            }

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }




            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
}
}
